import { Toast } from "vant";
import {  updateNotifyStatus } from "@/request/notify-request";
import {  addFriend , addGroupMember } from "@/request/add-request";

export const useUpdateNotifyStatus = async (item,type) => {
     try{
        const  result  = await updateNotifyStatus(item._id)   
        if(result.code === 201 && result.message === "success"){
           Toast("同意成功")
           console.log(item); 
           if(type === "friend"){
              await addFriend(item.to_id,item.from_id)
              await addFriend(item.from_id,item.to_id)
           }else if(type === "group"){
              await addGroupMember(item.from_id,item.group_id)
           }else{
               Toast("未知的请求类型")
           }
           location.reload();
        }else{
          Toast(result.message)
        }
     }catch(error){
        Toast(error.message)
     }
}
